package com.cgnpc.scp.purchase.controller;

import cn.com.cgnpc.aep.bizcenter.appcenter.sdk.result.ApiResult;
import com.cgnpc.cud.annotation.OperatorType;
import com.cgnpc.cud.annotation.UBA;
import com.cgnpc.cud.core.domain.AjaxResult;
import com.cgnpc.scp.common.bean.MyPageResult;
import com.cgnpc.scp.common.utils.AjaxResultUtil;
import com.cgnpc.scp.purchase.mybatis.entity.*;
import com.cgnpc.scp.purchase.service.IDemandQueryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/******************************
 * 用途说明: 年度需求
 * 作者姓名: chenshijie
 * 创建时间: 2020/09/23 22:47
 ******************************/
@RestController
@RequestMapping("/scp/purchase/demand")
public class DemandQueryController {

    private static final Logger LOGGER = LoggerFactory.getLogger(DemandQueryController.class);

    @Autowired
    private MessageSource messageSource;

    @Autowired
    private IDemandQueryService demandQueryService;

    /**********************************
     * 用途说明: 年度需求查询
     * 参数说明 params
     * 返回值说明:
     ***********************************/
    @PostMapping("/contractQuery")
//    @RequiresPermissions("win_add")
    @UBA(module = "调试采购",action = "年度需求查询",channel = OperatorType.Button)
    public AjaxResult contractQuery(HttpServletRequest request, @RequestBody ViewDemandQuery viewDemandQuery) {
        try {
            MyPageResult<ViewDemandQuery> viewDemandQueryMyPageResult = demandQueryService.contractQuery(viewDemandQuery);
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,viewDemandQueryMyPageResult);
        } catch (Exception e) {
            LOGGER.error("ContractProcessController insertContract error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 年度需求变更查询
     * 参数说明 params
     * 返回值说明:
     ***********************************/
    @PostMapping("/changeQuery")
//    @RequiresPermissions("win_add")
    @UBA(module = "调试采购",action = "年度需求变更查询",channel = OperatorType.Button)
    public AjaxResult changeQuery(HttpServletRequest request, @RequestBody ViewDemandChange viewDemandChange) {
        try {
            MyPageResult<ViewDemandChange> viewDemandChangeMyPageResult = demandQueryService.changeQuery(viewDemandChange);
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,viewDemandChangeMyPageResult);
        } catch (Exception e) {
            LOGGER.error("ContractProcessController insertContract error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 为变更流程提供需求查询
     * 参数说明 params
     * 返回值说明:
     ***********************************/
    @PostMapping("/queryPurchaseDemand")
//    @RequiresPermissions("win_add")
    @UBA(module = "调试采购",action = "为变更流程提供需求查询",channel = OperatorType.Button)
    public AjaxResult queryPurchaseDemand(HttpServletRequest request, @RequestBody ViewPurchaseDemand viewPurchaseDemand) {
        try {
            MyPageResult<ViewPurchaseDemand> viewDemandQueryMyPageResult = demandQueryService.queryPurchaseDemand(viewPurchaseDemand);
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,viewDemandQueryMyPageResult);
        } catch (Exception e) {
            LOGGER.error("ContractProcessController insertContract error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 为关闭流程提供需求查询
     * 参数说明 params
     * 返回值说明:
     ***********************************/
    @PostMapping("/queryCloseDemand")
//    @RequiresPermissions("win_add")
    @UBA(module = "调试采购",action = "为变更流程与关闭流程提供需求查询",channel = OperatorType.Button)
    public AjaxResult queryCloseDemand(HttpServletRequest request, @RequestBody ViewCLoseDemand viewCLoseDemand) {
        try {
            MyPageResult<ViewCLoseDemand> viewDemandQueryMyPageResult = demandQueryService.queryCloseDemand(viewCLoseDemand);
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,viewDemandQueryMyPageResult);
        } catch (Exception e) {
            LOGGER.error("ContractProcessController insertContract error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

}
